--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Commit b2517d8c829a5dd482cbf18acd5e727754dab3f1
Parents : a813e84
Author : Mark Qvist <mark@unsigned.io>
Date : 2024-09-08T17:50:19+02:00
Added stamp cost settings to UI
Changes
3 files changed, 89 insertions(+), 10 deletions(-)
Diff
diff --git a/sbapp/main.py b/sbapp/main.py
index a22a6990..9912c23e 100644
--- a/sbapp/main.py
+++ b/sbapp/main.py
@@ -2718,6 +2718,16 @@ class SidebandApp(MDApp):
self.settings_screen.ids.settings_print_command.text = self.sideband.config["print_command"]
self.sideband.save_configuration()
+ def save_lxmf_stamp_cost(sender=None, event=None, save=True):
+ if self.settings_screen.ids.settings_lxmf_require_stamps.active:
+ self.widget_hide(self.settings_screen.ids.lxmf_costslider_container, False)
+ else:
+ self.widget_hide(self.settings_screen.ids.lxmf_costslider_container, True)
+
+ if save:
+ self.sideband.config["lxmf_require_stamps"] = self.settings_screen.ids.settings_lxmf_require_stamps.active
+ self.sideband.save_configuration()
+
def save_lxmf_periodic_sync(sender=None, event=None, save=True):
if self.settings_screen.ids.settings_lxmf_periodic_sync.active:
self.widget_hide(self.settings_screen.ids.lxmf_syncslider_container, False)
@@ -2748,6 +2758,19 @@ class SidebandApp(MDApp):
self.sideband.config["lxmf_sync_interval"] = interval
self.sideband.save_configuration()
+ def stamp_cost_change(sender=None, event=None, save=True):
+ slider_val = int(self.settings_screen.ids.settings_lxmf_require_stamps_cost.value)
+ cost_text = str(slider_val)
+
+ self.settings_screen.ids.settings_lxmf_require_stamps_label.text = f"Require stamp cost {cost_text} for inbound messages"
+ if save:
+ if slider_val > 32:
+ slider_val = 32
+ if slider_val < 1:
+ slider_val = 1
+ self.sideband.config["lxmf_inbound_stamp_cost"] = slider_val
+ self.sideband.save_configuration()
+
self.settings_screen.ids.settings_lxmf_address.text = RNS.hexrep(self.sideband.lxmf_destination.hash, delimit=False)
self.settings_screen.ids.settings_identity_hash.text = RNS.hexrep(self.sideband.lxmf_destination.identity.hash, delimit=False)
@@ -2814,6 +2837,22 @@ class SidebandApp(MDApp):
self.settings_screen.ids.settings_lxmf_sync_interval.value = self.interval_to_slider_val(self.sideband.config["lxmf_sync_interval"])
sync_interval_change(save=False)
+ self.settings_screen.ids.settings_lxmf_require_stamps.active = self.sideband.config["lxmf_require_stamps"]
+ self.settings_screen.ids.settings_lxmf_require_stamps.bind(active=save_lxmf_stamp_cost)
+ save_lxmf_stamp_cost(save=False)
+
+ def stamp_cost_change_cb(sender=None, event=None):
+ stamp_cost_change(sender=sender, event=event, save=False)
+ self.settings_screen.ids.settings_lxmf_require_stamps_cost.bind(value=stamp_cost_change_cb)
+ self.settings_screen.ids.settings_lxmf_require_stamps_cost.bind(on_touch_up=stamp_cost_change)
+ cost_val = self.sideband.config["lxmf_inbound_stamp_cost"]
+ if cost_val == None or cost_val < 1:
+ cost_val = 1
+ if cost_val > 32:
+ cost_val = 32
+ self.settings_screen.ids.settings_lxmf_require_stamps_cost.value = cost_val
+ stamp_cost_change(save=False)
+
if self.sideband.config["lxmf_sync_limit"] == None or self.sideband.config["lxmf_sync_limit"] == False:
sync_limit = False
else:
diff --git a/sbapp/sideband/core.py b/sbapp/sideband/core.py
index 1348aec6..a9cb6653 100644
--- a/sbapp/sideband/core.py
+++ b/sbapp/sideband/core.py
@@ -215,7 +215,6 @@ class SidebandCore():
self.saving_configuration = False
self.last_lxmf_announce = 0
self.last_if_change_announce = 0
- self.inbound_stamp_cost = None
self.interface_local_adding = False
self.next_auto_announce = time.time() + 60*(random.random()*(SidebandCore.AUTO_ANNOUNCE_RANDOM_MAX-SidebandCore.AUTO_ANNOUNCE_RANDOM_MIN)+SidebandCore.AUTO_ANNOUNCE_RANDOM_MIN)
@@ -2717,13 +2716,19 @@ class SidebandCore():
self.message_router.set_inbound_stamp_cost(self.lxmf_destination.hash, self.config["lxmf_inbound_stamp_cost"])
self.message_router.announce(self.lxmf_destination.hash, attached_interface=attached_interface)
else:
- # TODO: Remove this announce option when LXMF 0.5.0 is deployed
+ self.message_router.set_inbound_stamp_cost(self.lxmf_destination.hash, None)
self.lxmf_destination.announce(attached_interface=attached_interface)
self.last_lxmf_announce = time.time()
self.next_auto_announce = time.time() + 60*(random.random()*(SidebandCore.AUTO_ANNOUNCE_RANDOM_MAX-SidebandCore.AUTO_ANNOUNCE_RANDOM_MIN)+SidebandCore.AUTO_ANNOUNCE_RANDOM_MIN)
RNS.log("Next auto announce in "+RNS.prettytime(self.next_auto_announce-time.time()), RNS.LOG_DEBUG)
self.setstate("wants.announce", False)
+
else:
+ if self.config["lxmf_require_stamps"]:
+ self.message_router.set_inbound_stamp_cost(self.lxmf_destination.hash, self.config["lxmf_inbound_stamp_cost"])
+ else:
+ self.message_router.set_inbound_stamp_cost(self.lxmf_destination.hash, None)
+
self.setstate("wants.announce", True)
def run_telemetry(self):
@@ -2805,11 +2810,6 @@ class SidebandCore():
self.latest_packed_telemetry = packed_telemetry
self.setstate("app.flags.last_telemetry", time.time())
- # TODO: Remove
- # tbt = Telemeter.from_packed(packed_telemetry)
- # tbts = tbt.read_all()["time"]["utc"]
- # RNS.log("TELEMETRY CHANGED, TIMEBASE IS NOW "+str(tbts))
-
if self.is_client:
try:
self.service_set_latest_telemetry(self.latest_telemetry, self.latest_packed_telemetry)
@@ -3669,9 +3669,17 @@ class SidebandCore():
self.message_router = LXMF.LXMRouter(identity = self.identity, storagepath = self.lxmf_storage, autopeer = True, delivery_limit = lxm_limit)
self.message_router.register_delivery_callback(self.lxmf_delivery)
- self.lxmf_destination = self.message_router.register_delivery_identity(self.identity, display_name=self.config["display_name"], stamp_cost=self.inbound_stamp_cost)
+ configured_stamp_cost = None
+ if self.config["lxmf_require_stamps"]:
+ configured_stamp_cost = self.config["lxmf_inbound_stamp_cost"]
+
+ self.lxmf_destination = self.message_router.register_delivery_identity(self.identity, display_name=self.config["display_name"], stamp_cost=configured_stamp_cost)
+
# TODO: Update to announce call in LXMF when full 0.5.0 support is added (get app data from LXMRouter instead)
- self.lxmf_destination.set_default_app_data(self.get_display_name_bytes)
+ # Currently overrides the LXMF routers auto-generated announce data so that Sideband will announce old-format
+ # LXMF announces if require_stamps is disabled.
+ # if not self.config["lxmf_require_stamps"]:
+ # self.lxmf_destination.set_default_app_data(self.get_display_name_bytes)
self.rns_dir = RNS.Reticulum.configdir
@@ -3771,7 +3779,7 @@ class SidebandCore():
desired_method = LXMF.LXMessage.PAPER
# TODO: Should paper messages also include a ticket to trusted peers?
- lxm = LXMF.LXMessage(dest, source, content, title="", desired_method=desired_method, fields = self.get_message_fields(destination_hash))
+ lxm = LXMF.LXMessage(dest, source, content, title="", desired_method=desired_method, fields = self.get_message_fields(destination_hash), include_ticket=self.is_trusted(destination_hash))
self.lxm_ingest(lxm, originator=True)
diff --git a/sbapp/ui/layouts.py b/sbapp/ui/layouts.py
index b0ce0ed3..dc833e9b 100644
--- a/sbapp/ui/layouts.py
+++ b/sbapp/ui/layouts.py
@@ -1603,6 +1603,38 @@ MDScreen:
sensitivity: "all"
hint: False
+ MDBoxLayout:
+ orientation: "horizontal"
+ size_hint_y: None
+ padding: [0,0,dp(24),dp(0)]
+ height: dp(48)
+
+ MDLabel:
+ id: settings_lxmf_require_stamps_label
+ text: "Require stamps for inbound messages"
+ font_style: "H6"
+
+ MDSwitch:
+ id: settings_lxmf_require_stamps
+ pos_hint: {"center_y": 0.3}
+ disabled: False
+ active: False
+
+ MDBoxLayout:
+ id: lxmf_costslider_container
+ orientation: "vertical"
+ size_hint_y: None
+ padding: [0,0,dp(0),0]
+ height: dp(68)
+
+ MDSlider
+ min: 1
+ max: 32
+ value: 8
+ id: settings_lxmf_require_stamps_cost
+ sensitivity: "all"
+ hint: False
+
MDBoxLayout:
orientation: "horizontal"
size_hint_y: None
──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────